package ran.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageInfo;
import ran.entity.Result;
import ran.entity.TableDataInfo;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ran
 * Date: 2025-10-12
 * Time: 15:07
 */
public class BaseController {
    public Result<Void> toResult(int result) {
        return result > 0 ? Result.ok() : Result.fail();
    }

    public Result<Void> toResult(boolean result) {
        return result ? Result.ok() : Result.fail();
    }
    public TableDataInfo toTableDataInfo(List<?> list) {
        if (CollectionUtil.isEmpty(list)) {
            return TableDataInfo.empty();
        }
        // 分压插件提供的查询数据总数的方法
        long total = new PageInfo<>(list).getTotal();
        return TableDataInfo.success(list,total);
    }
}
